/*
 * @Author: Dannycjh 2233879049@qq.com
 * @Date: 2023-04-14 19:00:12
 * @LastEditors: Dannycjh 2233879049@qq.com
 * @LastEditTime: 2023-04-15 12:15:56
 * @FilePath: \cc-game-development-template\assets\scripts\language\LanguageLabel.ts
 */
import { _decorator, Component, Label } from 'cc';
import { App } from '../App';
import { EventConst } from '../common/Common';

const { ccclass, property } = _decorator;

/**
 *文字翻译脚本
 *  */
@ccclass('LanguageLabel')
export class LanguageLabel extends Component {
    @property({ type: Number || String, tooltip: '文字对应ID' })
    private textId: number = 0;


    upDataLabel() {
        if (!this?.node?.getComponent(Label)) return;
        this.node.getComponent(Label).enableWrapText = true
        this.node.getComponent(Label).string = App.language.getLanguageLab(this.textId);
    }

    protected onLoad(): void {
        App.language.init()
    }

    start() {
        App.Event.on(EventConst.CHANGE_LANGUAGE, this.upDataLabel, this)
        this.upDataLabel()
    }

    update(deltaTime: number) {

    }

    onDestroy() {
        App.Event.off(EventConst.CHANGE_LANGUAGE, this.upDataLabel, this)
    }
}

